1567A - Domino Disaster - CodeForces Solution


Sorting *800

Please click on ads to support us..

Python Code:

class Solution:
    def find(self, string: str) -> str:
        another = ""
        
        for i in string:
            if i in "LR":
                another+= i
            else:
                if i == "U":
                    another+= "D"
                else:
                    another+= "U"
        return another

t = int(input())
for i in range(t):
    n = int(input())
    print(Solution().find(input()))
    

C++ Code:

#include<bits/stdc++.h>
using namespace std;
# define ll long long int
# define scan(arr,v,w) for(int i=v;i<w;i++) cin>>arr[i];
# define print(arr,v,w) for(int i=v;i<w;i++) cout<<arr[i]<<" ";
# define tc ll t;cin>>t;  while(t--)
# define fast ios::sync_with_stdio(0);cin.tie(0);
# define endl "\n"
 
int main(){
	fast;
//***********************************************************************************************************************************************************************************************
//dry run is necessary
//see corner cases 
tc{
int p;
cin>>p;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(s[i]=='L' ||s[i]=='R'){
	cout<<s[i];
}else if(s[i]=='U'){

cout<<"D";
}else if(s[i]=='D'){

cout<<"U";
}

}
cout<<endl;	
}


//***********************************************************************************************************************************************************************************************
		return 0;	
}
 
 


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament